package com.edu.homework;

import java.util.Random;
import java.util.Scanner;

public class HomeWork01 {

    public static void main(String[] args) {

        A a = new A();
        a.start();
        new B(a).start();
    }
}

class B extends Thread {
    A a;

    public B(A a) {
        this.a = a;
    }

    @Override
    public void run() {

        while (true) {
            System.out.println("请输入指令 @_@");
            Scanner scanner = new Scanner(System.in);
            char c = scanner.next().toUpperCase().charAt(0);
            if (c == 'Q') {
                a.setFlag(false);
                break;
            }
        }

    }
}

class A extends Thread {
    boolean flag = true;

    public void setFlag(boolean flag) {
        this.flag = flag;
    }

    @Override
    public void run() {
        while (flag) {
            System.out.println(new Random().nextInt(100));
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println("A 退出");
    }
}
